package Formularios;

import static DataBase.DataBase.*;
import static Dao.AgendamentoDao.*;
import static Dao.PacienteDao.*;
import DataBase.Resultado;
import Model.Agendamento;
import Model.Medicos;
import Model.Paciente;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author Cleiviane
 */
public class Cadastro_Agendamento extends javax.swing.JInternalFrame {

    Agendamento agendamento;
    Paciente paciente;
    Vector<Integer> medicos = new Vector<Integer>();

    /** Creates new form Agendamento */
    public Cadastro_Agendamento() {
        initComponents();
        ConectarDataBase();
        preencherComboMedicos();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        txtProntuario = new javax.swing.JTextField();
        txtCodigo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtPaciente = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cboMedico = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        txtData = new javax.swing.JTextField();
        botaoAlterar = new javax.swing.JButton();
        botaoDesmarcar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        botaoNovo = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        txtHora = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        botaoAgendar = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        cboStatus = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Agendamentos - SISAM");

        jLabel3.setText("Prontuário:");

        txtProntuario.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtProntuarioFocusLost(evt);
            }
        });

        txtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoActionPerformed(evt);
            }
        });
        txtCodigo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCodigoFocusLost(evt);
            }
        });

        jLabel4.setText("Cód. Agend.:");

        jLabel5.setText("Paciente:");

        txtPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPacienteActionPerformed(evt);
            }
        });

        jLabel6.setText("Médico:");

        cboMedico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboMedicoActionPerformed(evt);
            }
        });

        jLabel7.setText("Data:");

        txtData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDataActionPerformed(evt);
            }
        });

        botaoAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/alterar.jpg"))); // NOI18N
        botaoAlterar.setText("Alterar");
        botaoAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoAlterar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoAlterar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlterarActionPerformed(evt);
            }
        });

        botaoDesmarcar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/excluir.jpg"))); // NOI18N
        botaoDesmarcar.setText("Desmarcar");
        botaoDesmarcar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoDesmarcar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoDesmarcar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoDesmarcar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoDesmarcarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/cancelar.jpg"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        botaoNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/novo.jpg"))); // NOI18N
        botaoNovo.setText("Novo");
        botaoNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoNovo.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoNovoActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Monotype Corsiva", 1, 24)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(51, 51, 255));
        jLabel8.setText("Agendamento de Consultas");

        txtHora.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHoraActionPerformed(evt);
            }
        });

        jLabel10.setText("Hora:");

        botaoAgendar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/icone_agendamento.jpg"))); // NOI18N
        botaoAgendar.setText("Agendar");
        botaoAgendar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoAgendar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoAgendar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoAgendar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAgendarActionPerformed(evt);
            }
        });

        jLabel11.setText("Status:");

        cboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<Informe o status>", "Confirmada", "Cancelada", "Remarcada", "Agendada", "Finalizada" }));

        jLabel12.setText("DD/MM/AAAA");

        jLabel13.setText("HH:MM");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(56, 56, 56)
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(cboMedico, javax.swing.GroupLayout.PREFERRED_SIZE, 476, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(66, 66, 66)
                                .addComponent(jLabel7)
                                .addGap(18, 18, 18)
                                .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(jLabel12))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(66, 66, 66)
                                .addComponent(jLabel10)
                                .addGap(18, 18, 18)
                                .addComponent(txtHora, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(jLabel13))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addComponent(botaoAgendar, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(botaoAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(botaoDesmarcar, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(botaoNovo))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(48, 48, 48)
                                        .addComponent(jLabel5))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(36, 36, 36)
                                        .addComponent(jLabel3)))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtProntuario, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 476, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 587, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botaoAlterar, botaoDesmarcar, botaoNovo, btnCancelar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel4))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtProntuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(txtPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel6))
                    .addComponent(cboMedico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel7))
                    .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel12)))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel10))
                    .addComponent(txtHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel13)))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botaoAgendar)
                    .addComponent(botaoAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoDesmarcar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(92, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoActionPerformed
		// TODO add your handling code here:
}//GEN-LAST:event_txtCodigoActionPerformed

	private void txtPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPacienteActionPerformed
		// TODO add your handling code here:
	}//GEN-LAST:event_txtPacienteActionPerformed

	private void txtDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDataActionPerformed
		// TODO add your handling code here:
	}//GEN-LAST:event_txtDataActionPerformed

        private void botaoDesmarcarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoDesmarcarActionPerformed
            if(agendamento == null){
                JOptionPane.showMessageDialog(this, "Selecione algum agendamento para excluir!");
                return;
            }else{
                boolean result = JOptionPane.showInternalConfirmDialog(this, "Deseja realmente excluir esse agendamento?") == 0;
                if(result == true){
                        excluirAgendamento(agendamento.getCodigo());
                        JOptionPane.showMessageDialog(this, "Paciente Excluído com sucesso!");
                        limparCampos();
                        txtProntuario.requestFocusInWindow();
                } else
                    return;
            }
        }//GEN-LAST:event_botaoDesmarcarActionPerformed

        private void botaoAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlterarActionPerformed
            this.destravaCampos();
            txtCodigo.setEditable(false);
            btnCancelar.setEnabled(true);
            botaoAgendar.setEnabled(true);
            botaoAlterar.setEnabled(false);
            botaoDesmarcar.setEnabled(false);
            botaoNovo.setEnabled(false); 
        }//GEN-LAST:event_botaoAlterarActionPerformed

        private void txtHoraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHoraActionPerformed
            // TODO add your handling code here:
        }//GEN-LAST:event_txtHoraActionPerformed

        private void botaoAgendarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAgendarActionPerformed
            agendamento = new Agendamento();
            agendamento.setCodigo(Integer.parseInt(txtCodigo.getText()));
            agendamento.setMedico(cboMedico.getSelectedIndex());
            agendamento.setData(txtData.getText());
            agendamento.setHora(txtHora.getText());
            agendamento.setPaciente(txtPaciente.getText());
            agendamento.setProntuario(Integer.parseInt(txtProntuario.getText()));
            agendamento.setStatus(cboStatus.getSelectedIndex());

            if(txtCodigo.isEditable()){
                if(inserirAgendamento(agendamento))
                    JOptionPane.showMessageDialog(null, "Agendamento Efetuado.");
                else
                    JOptionPane.showMessageDialog(null, "Erro ao Gravar os Dados.");
                limparCampos();
                destravaCampos();
                botaoAlterar.setEnabled(false);
                botaoDesmarcar.setEnabled(false);
                botaoNovo.setEnabled(true);
                botaoAgendar.setEnabled(true);
                
            }else{
                if(alterarAgendamento(agendamento)){
                    travaCampos();
                    botaoAlterar.setEnabled(true);
                    botaoDesmarcar.setEnabled(true);
                    botaoAgendar.setEnabled(true);
                    botaoNovo.setEnabled(true);
                    btnCancelar.setEnabled(false);
                    JOptionPane.showMessageDialog(null, "As alterações foram salvas.");
                }
            }
        }//GEN-LAST:event_botaoAgendarActionPerformed

        private void txtProntuarioFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProntuarioFocusLost
            int prontuarioPaciente = Integer.parseInt(txtProntuario.getText());
            paciente = localizarPacientePorCodigo(prontuarioPaciente);
            txtPaciente.setText(paciente.getNome());
        }//GEN-LAST:event_txtProntuarioFocusLost

        private void txtCodigoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCodigoFocusLost
            int codigoAgend = Integer.parseInt(txtCodigo.getText());
            agendamento = localizarAgendamentoPorCodigo(codigoAgend);

            if(agendamento!=null){
                txtData.setText(agendamento.getData());
                txtHora.setText(agendamento.getHora());
                txtPaciente.setText(agendamento.getPaciente());
                txtProntuario.setText(String.valueOf(agendamento.getProntuario()));
                cboMedico.setSelectedIndex(agendamento.getMedico());
                this.travaCampos();
                botaoAlterar.setEnabled(true);
                botaoDesmarcar.setEnabled(true);
                botaoNovo.setEnabled(true);
                botaoAgendar.setEnabled(false);
            }
        }//GEN-LAST:event_txtCodigoFocusLost

        private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
            if(txtCodigo.getText().isEmpty()){
                    Cadastro_Agendamento.this.dispose();
                    botaoAlterar.setEnabled(false);
                    btnCancelar.setEnabled(false);
                    botaoDesmarcar.setEnabled(false);
                    botaoNovo.setEnabled(true);
                    botaoAgendar.setEnabled(false);
                    destravaCampos();
            }else
                {
                    botaoAlterar.setEnabled(true);
                    btnCancelar.setEnabled(false);
                    botaoDesmarcar.setEnabled(true);
                    botaoNovo.setEnabled(true);
                    botaoAgendar.setEnabled(false);
                    travaCampos();
                }
        }//GEN-LAST:event_btnCancelarActionPerformed

        private void botaoNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoNovoActionPerformed
            limparCampos();
            destravaCampos();
            txtCodigo.setEditable(true);
            txtCodigo.requestFocus();
            botaoAlterar.setEnabled(false);
            botaoDesmarcar.setEnabled(true);
            //botaoExcluir.setEnabled(false);
            botaoNovo.setEnabled(false);
            //botaoSalvar.setEnabled(true);
        }//GEN-LAST:event_botaoNovoActionPerformed

        private void cboMedicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboMedicoActionPerformed
            
        }//GEN-LAST:event_cboMedicoActionPerformed

         private void limparCampos() {
            txtProntuario.setText(null);
            txtPaciente.setText(null);
            txtCodigo.setText(null);
            txtData.setText(null);
            txtHora.setText(null);
            cboMedico.setSelectedItem(null);
        }

        private void travaCampos(){
            txtProntuario.setEditable(false);
            txtPaciente.setEditable(false);
            txtCodigo.setEditable(false);
            txtData.setEditable(false);
            txtHora.setEditable(false);
            cboMedico.setEditable(false);
        }

        private void destravaCampos(){
           txtProntuario.setEditable(true);
            txtPaciente.setEditable(true);
            txtCodigo.setEditable(true);
            txtData.setEditable(true);
            txtHora.setEditable(true);
            cboMedico.setEditable(true);
    }

    private void preencherComboMedicos() {
        cboMedico.addItem("<Selecione um médico>");
        medicos.add(0);

        Resultado rs = executaConsulta("select * from medicos order by nome", new Object[0]);

        for(int i=0; i< rs.qtdRegistros(); i++){
            cboMedico.addItem(rs.valorCampo(i, "Nome"));
            medicos.add((Integer)rs.valorCampo(i, "codigo"));

            int n = medicos.indexOf((Integer) rs.valorCampo(i, "estado"));
            cboMedico.setSelectedIndex(n);
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAgendar;
    private javax.swing.JButton botaoAlterar;
    private javax.swing.JButton botaoDesmarcar;
    private javax.swing.JButton botaoNovo;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JComboBox cboMedico;
    private javax.swing.JComboBox cboStatus;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtData;
    private javax.swing.JTextField txtHora;
    private javax.swing.JTextField txtPaciente;
    private javax.swing.JTextField txtProntuario;
    // End of variables declaration//GEN-END:variables

    
}
